package userTests;

import org.openqa.selenium.By;
import org.testng.annotations.Test;

public class TransferTests extends TestBaseUser {

	@Test
	public void testTransfer() throws InterruptedException {
		openMainPageUser();
		gotoSignInUser();
		LoginLogoutDataUser signIn = new LoginLogoutDataUser();
		signIn.phoneNumber = "955413233";
		signIn.password = "!23Qwe";
		fillSignInUser(signIn);
		submitSignInUser();

//		isAntiFishingImgPresent();
		pointCurrency();
		gotoTransfer();
		fillTransferForm();

		if (!wd.findElement(By.id("has_protection")).isSelected()) {
			wd.findElement(By.id("has_protection")).click();
		}

		selectCheckBoxProtection();
		editProtectionCode();
		gotoPreviewTransfer();

		gotoEditTransferForm();
		editTransferForm();
		gotoPreviewTransfer();
		
		fillInvalidPayPassword();
		confirmTransfer();
		isAlertErrorBlockPresent();
		
		fillValidPayPassword();
		confirmTransfer();
		isAlertSuccessBlockPresent();

		pointCurrency();
		logout();
		confirmMainPageUser();
	}

	protected void fillTransferForm() {
		wd.findElement(By.id("amount_integer")).click();
		wd.findElement(By.id("amount_integer")).clear();
		wd.findElement(By.id("amount_integer")).sendKeys("15");
		wd.findElement(By.id("contragent")).click();
		wd.findElement(By.id("contragent")).clear();
		wd.findElement(By.id("contragent")).sendKeys("+");
		wd.findElement(By.id("contragent")).click();
		wd.findElement(By.id("contragent")).clear();
		wd.findElement(By.id("contragent")).sendKeys("+380997047402");
		wd.findElement(By.id("comments")).click();
		wd.findElement(By.id("comments")).clear();
		wd.findElement(By.id("comments")).sendKeys("auto11");
	}

	protected void editTransferForm() {
		wd.findElement(By.id("amount_integer")).click();
		wd.findElement(By.id("amount_integer")).clear();
		wd.findElement(By.id("amount_integer")).sendKeys("11");
		wd.findElement(By.id("contragent")).click();
		wd.findElement(By.id("contragent")).clear();
		wd.findElement(By.id("contragent")).sendKeys("+380999999998");
		wd.findElement(By.id("comments")).click();
		wd.findElement(By.id("comments")).clear();
		wd.findElement(By.id("comments")).sendKeys("q11");
	}

	private void selectCheckBoxProtection() {
		wd.findElement(By.id("has_protection")).click();
	}

	private void editProtectionCode() {
		wd.findElement(By.id("protection_code")).click();
		wd.findElement(By.id("protection_code")).clear();
		wd.findElement(By.id("protection_code")).sendKeys("1111");
		wd.findElement(By.id("period_days")).click();
		wd.findElement(By.id("period_days")).clear();
		wd.findElement(By.id("period_days")).sendKeys("2");
	}

}
